<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 2017/9/29
 * Time: 8:15
 */

namespace a;


class Personal
{
    public $name = "张三";
    private $age = 20;
    public $sex = "男";

    function __construct()
    {
        //未加this指向类字段的话默认为局部变量
        echo "hello";
        $this->name = "杨邦城";
        //$name="张三";
       // echo $name;
        $this->age = "20";
        $this->sex = "男";
    }
    public function __set($name,$value)
    {
        if($name=='age')
        {
            $this->age==(($value<0)?1:$value);
        }
        $this->age=$value;
    }
    public function say()
    {
        echo "我的姓名是:"  .$this->name ."<br/>" . "我的年龄是:" . $this->age ."<br/>" . "我的性别是:" . $this->sex."<br/>";
    }

}

$a = new personal();
$a->say();
$a->age=0;
$a->say();
